/////////////////////////////////////////////////////////////////////////////
// Name:        ax_module_audio.h
// Purpose:     Audio module classes
// Author:      Julian Smart
// Modified by:
// Created:     2009-03-20
// RCS-ID:
// Copyright:   (c) Julian Smart
// Licence:     New BSD License
/////////////////////////////////////////////////////////////////////////////

#ifndef _AX_MODULE_AUDIO_H_
#define _AX_MODULE_AUDIO_H_

/*
 * Includes
 */

#include "ax/ax_view.h"

#include "ax_resource/ax_resource.h"
#include "ax_resource/ax_activator_resource.h"
#include "ax_resource/ax_module.h"

class AxMP3Info;

#define axPROPERTY_TRACK_POSITION wxT("Track position")

/**
    @class AxAudioResource

    A resource for audio files.

    @category{ax_resource}
 */

class AxAudioResource: public AxResource
{
    DECLARE_DYNAMIC_CLASS( AxAudioResource )

public:
// Constructors

    AxAudioResource(const AxAudioResource& resource) { Init(); Copy(resource); }
    AxAudioResource() { Init(); }
    ~AxAudioResource();

// Operations

    void Init();

    /// Copy the resource information.
    void Copy(const AxAudioResource& resource);

    /// Copy from MP3 information
    void CopyAlbumInfo(const AxMP3Info& info);

    /// Copy from MP3 information
    void CopyTrackInfo(const AxMP3Info& info);

    /// Clone - derived classes must implement this function.
    virtual AxDocument* Clone() const { return new AxAudioResource(*this); }


protected:

};

/**
    @class AxAudioView

    Handles UI for the audio view.

    @category{ax_resource}
 */

class AxMediaCtrlPanel;
class AxAudioView: public AxView
{
    DECLARE_DYNAMIC_CLASS( AxAudioView )

public:
// Constructors

    AxAudioView() { Init(); }
    ~AxAudioView() {}

// Operations

    void Init();

    virtual bool Activate(AxViewManager* viewManager, AxDocument* doc);
    virtual bool Deactivate(AxViewManager* viewManager);

    virtual bool Initialize(AxViewManager* viewManager);
    virtual bool Uninitialize(AxViewManager* viewManager);
    
    AxMediaCtrlPanel* GetMediaCtrlPanel() const;

    void ShowViewIfInactive();
    void SetPlaylist();
    bool PlayOrPause(AxResource* resource);
    bool Stop();
    bool ShowTrackDetails(AxResource* resource);

    bool AlbumShowDetails(AxResource* resource);
    bool AlbumPlayAll(AxResource* resource);
    bool AlbumPreviousTrack(AxResource* resource);
    bool AlbumNextTrack(AxResource* resource);

    AxAudioResource* GetResource() const;

protected:

};

/**
    @class AxAudioModule

    A module for dealing with audio files.

    @category{ax_resource}
 */

class AxAudioModule: public AxModule
{
DECLARE_DYNAMIC_CLASS(AxAudioModule)

public:
    /// Constructor.
    AxAudioModule();

    /// Destructor.
    ~AxAudioModule() {}

// Overridables

    /// Called on IDE startup, before the main window has been created.
    virtual bool OnInit();

    /// Called on application startup, after the main window has been created.
    virtual bool OnInitUI();

 	/// Called just before program termination, but only if OnInit()
    /// succeeded.
    virtual void OnExit();

	/// Read config settings
	virtual bool LoadConfig(wxConfigBase& config);

	/// Write config settings
    virtual bool SaveConfig(wxConfigBase& config);

    // Called just before the frame is closed. Return false vetoes
    // the frame/app close.
    virtual bool OnCloseMainWindow() { return true; }

    // Allows app to search amongst its own objects. Call AxResourceLibrary::AddSearchItem
    // for each item.
    virtual bool OnSearch(const wxString& WXUNUSED(searchString), int WXUNUSED(flags), AxResourceLibrary* WXUNUSED(library)) { return false; }

    /// Is this file supported?
    virtual bool IsFileSupported(const wxString& filename);

    /// Load the file into a new AxResource
    virtual AxResource* LoadResource(const wxString& filename);

    /// Aggregate any files that belong together and add to resources. Return false if you don't
    /// aggregate any files.
    virtual bool AggregateFiles(AxResourceLibrary* library, wxArrayString& files, bool checkIfFileLoaded);

    /// Create an activator for the resource, for creating views and further menu items.
    virtual AxActivator* CreateActivator(AxResourceLibrary* library, AxResource* resource);

// Accessors

protected:
};

/**
    @class AxAudioResourceActivator

    Activates an individual audio resource.

    @category{ax_resource}
 */

class AxAudioResourceActivator: public AxResourceActivator
{
public:
    
    DECLARE_DYNAMIC_CLASS( AxAudioResourceActivator )

public:
// Constructors

    AxAudioResourceActivator() { Init(); }
    AxAudioResourceActivator(const AxAudioResourceActivator& activator) { Init(); Copy(activator); }

    AxAudioResourceActivator(AxResourceLibrary* library, AxResource* resource);
    ~AxAudioResourceActivator() {}

// Operations

    void Init();

    void Copy(const AxAudioResourceActivator& activator);

    virtual AxActivator* Clone() const { return new AxAudioResourceActivator(*this); }

    virtual AxMenu* Activate(AxMenuController* controller, AxMenuItem* item);

    /// Called when a menu is reactivated, for example by going up. This
    /// allows a view to be shown again, without generating all the menus.
    virtual bool Reactivate(AxMenuController* controller, AxMenuItem* item);

protected:
};

/**
    @class AxAudioResourceCommandActivator

    Activates individual menu commands for individual audio resource,
    for example Play or Show Details.

    @category{ax_resource}
 */

class AxAudioResourceCommandActivator: public AxResourceActivator
{
public:
    
    DECLARE_DYNAMIC_CLASS( AxAudioResourceCommandActivator )

        typedef enum 
    {
        AxAudioResourceCommandUnknown,
            
            // At track level
            
            AxAudioResourceCommandPlay,
            AxAudioResourceCommandStop,
            AxAudioResourceCommandShowDetails,
            
            // At album level
            
            AxAudioResourceCommandAlbumPlayAll,
            AxAudioResourceCommandAlbumStop,
            AxAudioResourceCommandAlbumShowDetails,
            AxAudioResourceCommandAlbumNextTrack,
            AxAudioResourceCommandAlbumPreviousTrack
            
    } AxAudioResourceCommand;

public:
// Constructors

    AxAudioResourceCommandActivator() { Init(); }
    AxAudioResourceCommandActivator(const AxAudioResourceCommandActivator& activator) { Init(); Copy(activator); }

    AxAudioResourceCommandActivator(AxAudioResourceCommand cmd, AxResourceLibrary* library, AxResource* resource);
    ~AxAudioResourceCommandActivator() {}

// Operations

    void Init();

    void Copy(const AxAudioResourceCommandActivator& activator);

    virtual AxActivator* Clone() const { return new AxAudioResourceCommandActivator(*this); }

    virtual AxMenu* Activate(AxMenuController* controller, AxMenuItem* item);

protected:
    AxAudioResourceCommand  m_command;
};

#endif
    // _AX_MODULE_AUDIO_H_
